【异常】OS X 10.11( EI )上 Nginx 的 https moudle

开笔

自 OS X 10.11 起,Apple 对 OS X 系统的安全做了全新的升级,增加了诸多限制,如 我们再也不能 ln 自己编译安装的软件到 /usr/bin/usr/sbin 了;自带的 openssl不再有 libssl-deve 的库了。

笔者在使用 nginx 第三方库 nginx-upload-module的时候无法绕开 https编译库。使用了 brew 安装 libssl-devel 失败、使用源码编译 openssl 也没找到办法连接或者配置lib的路径。最终选择with-openssl选项编译。

具体问题

在 Mac 上做过源码编译安装 openssl 开发者一定知道知道,需要手动指定64位。否则贼会出现如下警告:

1
2
WARNING! If you wish to build 64-bit library, then you have to
invoke ‘./Configure darwin64-x86_64-cc’ *manually*.

因此,在 openssl 的编译配置中,使用 ./Configure darwin64-x86_64-cc ,即可顺利安装。

这个不难,但是,笔者在使用做 nginx 源码编译安装时,源码编译的 openssl (prefix 配置到 /usr/local/openssl) nginx 依然无法找到 ssl lib 的路径;

在 10.10 及其之前的 OS X 版本 prefix 不配置即可(默认 /usr/local),是可以找到 ssl lib 的。但这个在 10.11 版本系统中无法使用。

解决步骤

  1. 使用源码编译,分别下载nginx,openssl,pcre
  2. 准备编译nginx,记住先只进行 config ,不要急着 make

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    ./configure \
    --prefix=/usr/local/nginx \
    --user=Jiafan \
    --group=staff \
    --with-http_ssl_module \
    --with-http_realip_module \
    --with-http_ssl_module \
    --with-http_realip_module \
    --with-http_addition_module \
    --with-http_sub_module \
    --with-http_dav_module \
    --with-http_flv_module \
    --with-http_gzip_static_module \
    --with-http_stub_status_module \
    --with-mail \
    --with-mail_ssl_module \
    --with-pcre=/* source path to pcre */ \
    --with-openssl=/* source path to openssl */ \
    --add-module=/* source path to nginx upload module */
  3. 如果直接编译,openssl 会报错:

    1
    2
    WARNING! If you wish to build 64-bit library, then you have to
    invoke ‘./Configure darwin64-x86_64-cc’ *manually*.

如果你不停止编译就会出错。这个问题应该是 openssl/config脚本猜对你的系统是64位,但是 会根据$KERNEL_BITS来判断是否开启x86_64编译,默认 是不开启的(很奇怪的设置,虽然会给你5秒时间停止编译并手动开启),所以你生成的openssl库文件是32位的,最后静态链接到nginx会出错。目前看来没有很好的方法把x86_64的参数传到openssl配置文件中 (openssl/config 猜测os架构,设置编译的参数是32位还是64位,默认是32位,然后调用openssl/Configure生成Makefile)

4.进入nginx目录,手动修改 objs/Makefile:

1
./config –prefix=/Users/xxx/Downloads/openssl-1.0.1e/.openssl no-shared no-threads

改成

1
./Configure darwin64-x86_64-cc –prefix=/Users/xxx/Downloads/openssl-1.0.1e/.openssl no-shared no-threads

收工

后面进行 make 和 make install

PS

欢迎来到我github上的空间:https://jiafan.github.io